package com.base.cn.platform.os.controller.course.cou.play;

import com.base.cn.platform.os.common.utils.user.LoginForm;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.cou.play.PlayCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 课程播放接口Controller
 *
 * @author s.li
 * @create 2018-09-07-15:15
 */
@RestController
@RequestMapping("/api/play")
public class ApiCoursePlayController extends ApiBaseController {

    @Autowired
    private PlayCourseService playCourseService;

    /**
     * 验证播放
     * @param buyCourseId 课程/套餐ID（购买的课程ID）
     * @param courseId 课程ID
     * @param prevCatalogId  前一个目录ID
     * @param catalogId 章节id
     * @return Map<String,Object>
     */
    @RequestMapping("/checkPlay")
    public Map<String,Object> checkPlay(@RequestParam("userId") BigDecimal userId,
                                        @RequestParam("buyCourseId") BigDecimal buyCourseId,
                                        @RequestParam("courseId") BigDecimal courseId,
                                        @RequestParam("prevCatalogId") BigDecimal prevCatalogId,
                                        @RequestParam("catalogId") BigDecimal catalogId){
        Map<String,Object> resultMap = playCourseService.checkCourseCatalogPlay(buyCourseId,courseId,prevCatalogId, catalogId, userId);
        return resultMap;
    }

    /**
     * 获取播放数据
     * @param palySign （checkPlay接口返回的签名）
     * @return Map<String,Object>
     */
    @RequestMapping("/loadPlayData")
    public Map<String,Object> loadPlayData(@RequestParam("palySign") String palySign,
                                           @RequestParam(value = "nickname",required = false) String nickname,
                                           @RequestParam(value = "userAvatar",required = false) String userAvatar, @RequestParam(value = "userId",required = false) BigDecimal userId){
        return playCourseService.loadPlayData(palySign, LoginForm.LOGIN_FORM_APP,nickname,userAvatar,userId);
    }
}
